
public class Address {
	private String city;
	private String cap;
	private String way; 
	private int num;
	
	public Address(){}
	
	public Address(String city, String cap, String way, int num) {
		this.setCity(city);
		this.setCap(cap);
		this.setNum(num);
		this.setWay(way);
	}
	
	public Address(Address addr) {
		this.city = addr.city;
		this.cap = addr.cap;
		this.way = addr.way;
		this.num = addr.num;
	}
	
	public void setCity(String city) {
		if (city.matches("^[a-zA-Z ]+$")) {
			this.city = city;
		}
		else {
			// Formato nome non corretto
			System.out.println("err");
		}
	}
	
	public void setCap(String cap) {
		if (cap.matches("^[0-9]+$")) {
			this.cap = cap;
		}
		else {
			// Formato nome non corretto
			System.out.println("err");
		}
	}
	
	public void setWay(String way) {
		if (way.matches("^[a-zA-Z ]+$")) {
			this.way = way;
		}
		else {
			// Formato nome non corretto
			System.out.println("err");
		}
	}
	
	public void setNum(int num) {
		if (num > 0) {
			this.num = num;
		}
		else {
			// Formato nome non corretto
			System.out.println("err");
		}
	}
	
	public String getCity() {
		return this.city;
	}
	
	public String getCap() {
		return this.cap;
	}
	
	public String getWay() {
		return this.way;
	}
	
	public int getNum() {
		return this.num;
	}
	
	public String toString() {
		return this.city + ", "+ this.cap + " " + this.way + " " + this.num; 
	}
	
	protected Object clone() {
		return new Address(this);
	}
	
	public boolean equals(Object o) {
		Address temp = (Address) o;
		if(temp == this) return true;
		if(temp == null) return false;
		return temp.getCap().equals(this.cap) 
		&& temp.getCity().equals(this.city) 
		&& temp.getNum() == this.num 
		&& temp.getWay().equals(this.way);
	}
	
	
}
